package org.example.dao;

import org.example.entity.Article;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface ArticleDao extends JpaRepository<Article, Integer>, JpaSpecificationExecutor<Article> {

    //展示位置参数绑定
    @Query("from Article as a where a.author = ?1 and a.title = ?2")
    List<Article> findByCondition1(String author, String title);

    @Query("from Article a where a.author = :author and a.title = :title")
    List<Article> findByCondition2(@Param("author") String author, @Param("title") String title);


    //展示like模糊查询
    @Query("from Article as a where a.author like %:author%")
    List<Article> findByCondition3(@Param("author") String author);

    //展示排序查询
    @Query("from Article as a where a.title like %:title% order by a.aid desc")
    List<Article> findByCondition4(@Param("title") String title);

    //展示分页查询
    @Query("from Article as a where a.title like %:title% order by a.aid desc")
    List<Article> findByCondition5(@Param("title") String title, Pageable pageable);

    //展示传入集合参数查询
    @Query("from Article a where a.aid in :ids")
    List<Article> findByCondition6(@Param("ids") List<Integer> ids);


    //展示传入Bean进行查询（SPEL表达式查询）
    @Query("from Article a where a.title = :#{#article.title} and a.author = :#{#article.author}")
    List<Article> findByCondition7(@Param("article") Article article);


}
